package com.mentaleye.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.dal.dao.StudentPunchRecordDao;
import com.mentaleye.dal.model.StudentPunchRecord;
import com.mentaleye.dal.model.StudentPunchRecordExample;
import com.mentaleye.dal.model.StudentPunchRecordExample.Criteria;
import com.mentaleye.service.StudentPunchRecordService;

@Service
public class StudentPunchRecordServiceImpl implements StudentPunchRecordService {

	@Autowired
	private StudentPunchRecordDao recordDao;

	@Override
	public boolean insertByList(List<StudentPunchRecord> recordList) {
		return this.recordDao.insertByList(recordList);
	}

	@Override
	public boolean updateRecord(StudentPunchRecord record) {
		return this.recordDao.updateRecord(record);
	}
	
	@Override
	public List<Map<String,Object>> getListByMap(Map<String, Object> map) {
		return this.recordDao.getListByMap(map);
	}

	@Override
	public StudentPunchRecord getBySelective(int studentId, Date writeTime) {
		StudentPunchRecord punchRecord=null;
		StudentPunchRecordExample example=new StudentPunchRecordExample();
		Criteria criteria = example.createCriteria();
		criteria.andStudentIdEqualTo(studentId);
		criteria.andWriteTimeEqualTo(writeTime);
		List<StudentPunchRecord> recordList = this.recordDao.getListByExample(example);
		if(!recordList.isEmpty()){
			punchRecord=recordList.get(0);
		}
		return punchRecord;
	}
	
	@Override
	public List<StudentPunchRecord> getListBySelective(int studentId,Date writeTime) {
		StudentPunchRecordExample example=new StudentPunchRecordExample();
		Criteria criteria = example.createCriteria();
		criteria.andStudentIdEqualTo(studentId);
		criteria.andWriteTimeEqualTo(writeTime);
		return this.recordDao.getListByExample(example);
	}
	
	@Override
	public boolean deleteByWriteTime(Date writeTime) {
		return this.recordDao.deleteByWriteTime(writeTime);
	}

	@Override
	public StudentPunchRecord getRecordByKey(Long recordId) {
		StudentPunchRecord record=null;
		StudentPunchRecordExample example=new StudentPunchRecordExample();
		Criteria criteria = example.createCriteria();
		criteria.andRecordIdEqualTo(recordId);
		List<StudentPunchRecord> recordList = this.recordDao.getListByExample(example);
		if(!recordList.isEmpty()){
			record=recordList.get(0);
		}
		return record;
	}
}
